package com.xcode.unit.util;

import com.google.common.reflect.TypeToken;
import com.xcode.unit.constant.UnitTestClassConstants;
import com.xcode.unit.dto.PodamParameterizedType;
import org.springframework.util.ObjectUtils;
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
import uk.co.jemos.podam.api.PodamFactory;
import uk.co.jemos.podam.api.PodamFactoryImpl;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author liuziying
 * @Description 字符串工具类
 * @Date 2020/12/24
 */
public class LStringUtils {

    private LStringUtils(){}
    /**
     * 首字母转小写
     * @param sourceStr
     * @return
     */
    public static String toLowerCaseFirst(String sourceStr){
        if(Character.isLowerCase(sourceStr.charAt(0))){
            return sourceStr;
        }
        char[] chars = sourceStr.toCharArray();
        chars[0] += 32;
        return String.valueOf(chars);
    }

    /**
     * 首字母转小写
     * @param sourceStr
     * @return
     */
    public static String toUpperCaseFirst(String sourceStr){
        if(Character.isUpperCase(sourceStr.charAt(0))){
            return sourceStr;
        }
        char[] chars = sourceStr.toCharArray();
        chars[0] -= 32;
        return String.valueOf(chars);
    }

    /**
     * 按separator分割后，获取index字符
     * @param sourceStr
     * @param separator
     * @param index
     * @return
     */
    public static String getIndexCharacterBySeparator(String sourceStr, String separator, int index){
        if(ObjectUtils.isEmpty(sourceStr)){
            return sourceStr;
        }
        return sourceStr.split(separator)[index];
    }

    /**
     * 按separator分割后，获取Last字符
     * @param sourceStr
     * @param separator
     * @return
     */
    public static String getLastCharacterBySeparator(String sourceStr, String separator){
        if(ObjectUtils.isEmpty(sourceStr)){
            return sourceStr;
        }
        String[] split = sourceStr.split(separator);
        return split[split.length-1];
    }

    /**
     * 按separator分割后，获取First字符
     * @param sourceStr
     * @param separator
     * @return
     */
    public static String getFirstCharacterBySeparator(String sourceStr, String separator){
        if(ObjectUtils.isEmpty(sourceStr)){
            return sourceStr;
        }
        String[] split = sourceStr.split(separator);
        return split[0];
    }

    /**
     * 判断空 包含字符 null/NULL/""
     * @param obj
     * @return
     */
    public static boolean isEmptyAndNull(Object obj){
        if(ObjectUtils.isEmpty(obj)){
            return true;
        }
        obj = obj.toString().trim();
        return "null".equals(obj) || "NULL".equals(obj) || "".equals(obj) ? true : false;
    }
}
